package zengjin.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zengjin.common.R;
import zengjin.model.dto.collect.AddCollectRequest;
import zengjin.model.dto.collect.DeleteCollectRequest;
import zengjin.model.dto.collect.GetCollectRequest;
import zengjin.model.dto.collect.PageCollectRequest;
import zengjin.service.CollectService;

/**
 * @author 19324
 */
@Tag(name = "收藏相关接口")
@RestController
@RequestMapping("/collect")
@Slf4j
public class CollectController {

    @Resource
    private CollectService collectService;


    //1. 添加收藏
    @Operation(summary = "添加收藏")
    @PostMapping("/addCollect")
    public R<Boolean> addCollect(@RequestBody AddCollectRequest addCollectRequest) {
        //1. 参数校验
        if (addCollectRequest == null) {
            throw new RuntimeException("参数为空");
        }
        //2. 调用service
        Boolean addCollectResult = collectService.addCollect(addCollectRequest);
        if (!addCollectResult) {
            return R.error(false, "添加收藏失败");
        }
        return R.success(true, "添加收藏成功");
    }

    //2.取消收藏
    @Operation(summary = "取消收藏")
    @PostMapping("/deleteCollect")
    public R<Boolean> deleteCollect(@RequestBody DeleteCollectRequest deleteCollectRequest) {
        //1. 参数校验
        if (deleteCollectRequest == null) {
            throw new RuntimeException("参数为空");
        }
        //2. 调用service
        boolean deleteCollectResult = collectService.deleteCollect(deleteCollectRequest);
        if (!deleteCollectResult) {
            return R.error(false, "取消收藏失败");
        }
        return R.success(true, "取消收藏成功");
    }

    //3.查询收藏列表
    @Operation(summary = "查询收藏列表")
    @PostMapping("/pageCollect")
    public R<Object> pageCollect(@RequestBody PageCollectRequest pageCollectRequest) {
        //1. 参数校验
        if (pageCollectRequest == null) {
            throw new RuntimeException("参数为空");
        }
        //2. 调用service
        Object vo = collectService.pageCollect(pageCollectRequest);
        return R.success(vo, "查询收藏列表成功");
    }

    //4.查询收藏情况根据岗位ID
    @Operation(summary = "查询收藏情况根据岗位ID")
    @PostMapping("/getCollectByJobEmployerId")
    public R<Boolean> getCollectByJobEmployerId(@RequestBody GetCollectRequest getCollectRequest) {
        //1. 参数校验
        if (getCollectRequest == null ) {
            throw new RuntimeException("参数为空");
        }
        //2. 调用service
        boolean collectByJobEmployerId = collectService.getCollectByJobEmployerId(getCollectRequest);
        return R.success(collectByJobEmployerId,"查询收藏情况成功");
    }

}
